﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class UserControl_ControlLietKeDieuChinhTonKho : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState["strSoHoaDon"] != null && ViewState["strDate"] != null)
        {
            ControlReportViewer1.ReportViewer.Report = CreateReport(ViewState["strSoHoaDon"].ToString(), ViewState["strDate"].ToString());
        }
    }
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        GetDataBind();
    }
    protected void grdvNghiepVuNhanHangLists_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdvNghiepVuNhanHangLists.PageIndex = e.NewPageIndex;
        GetDataBind();
    }
    protected void grdvNghiepVuNhanHangLists_SelectedIndexChanged(object sender, EventArgs e)
    {
        string strSoHoaDon = grdvNghiepVuNhanHangLists.SelectedDataKey.Value.ToString();
        dt = new ClassExecute.ClassExecute();
        ViewState["strSoHoaDon"] = strSoHoaDon;
        ViewState["strDate"] = ((Label)grdvNghiepVuNhanHangLists.SelectedRow.FindControl("lblDate")).Text;
        ControlReportViewer1.ReportViewer.Report = CreateReport(strSoHoaDon, ViewState["strDate"].ToString());
        DataBind();
        UpdatePanel1.Update();
        TabContainer1.ActiveTabIndex = 1; 
    }
    void GetDataBind()
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getDocnoDieuChinhTonKhoToLietKe", CommandType.StoredProcedure,
                new SqlParameter("@sitecode", Session["sitecode"].ToString()),
                new SqlParameter("@date", txtFromDate.Text));
            if (db.Rows.Count > 0)
            {
                grdvNghiepVuNhanHangLists.DataSource = db;
            }
            else
            {
                grdvNghiepVuNhanHangLists.DataSource = null;
            }
            grdvNghiepVuNhanHangLists.DataBind();
        }
        catch (Exception ex)
        {
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            dt.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);
        }
    }

    DevExpress.XtraReports.UI.XtraReport CreateReport(string strSoHoaDon, string strDateOrder)
    {
        XtraReportInDieuChinhKho tableReport = new XtraReportInDieuChinhKho();
        if (Session["Sitecode"] != null)
        {
            string DocNo = strSoHoaDon;
            dt = new ClassExecute.ClassExecute();
            DataSet ds = new DataSet();

            ds = dt.Get_Data_DataSet(str, ref error, "TTr_getDocnoChiTietDieuChinhTonKhoToLietKe", CommandType.StoredProcedure,
                new SqlParameter("@docNo", DocNo),
                new SqlParameter("@siteCode", Session["Sitecode"].ToString()),
                new SqlParameter("@date", strDateOrder));

            tableReport.SetReportParameter(ds);
        }
        return tableReport;
    }
}